//
//  LRJFoodDetailViewController.m
//  BreadTravel
//
//  Created by 李润嘉 on 15/1/3.
//  Copyright © 2015年 李润嘉. All rights reserved.
//

#import "LRJFoodDetailViewController.h"

@interface LRJFoodDetailViewController ()<UIWebViewDelegate>
@property (nonatomic,assign)BOOL isFirst;
@end

@implementation LRJFoodDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //左面返回按钮
    UIImage *leftImage = [UIImage imageNamed:@"btn_nav_back@2x.png"];
    leftImage = [leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftImage style:UIBarButtonItemStyleDone target:self action:@selector(leftButtonAction:)];
    
    self.view.backgroundColor = [UIColor blackColor];
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -40, WIDTH, HEIGHT + 40)];
    self.webView.delegate = self;

    [self.view addSubview:self.webView];
    //取消边界回弹
    self.webView.scrollView.bounces = NO;
    
    self.juhua.hidesWhenStopped = YES;
    
    [self webViewMethod];
    
    
}
#pragma mark -- 左面返回按钮
//返回
-(void)leftButtonAction:(UIBarButtonItem *)bar{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)webViewMethod
{
    NSString *urlStr = [NSString stringWithFormat:@"http://m.ibantang.com/topic/detail/%@/", self.modelId];
    NSURL *url = [NSURL URLWithString:urlStr];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
}
#pragma mark -- 页面开始加载的时候
-(void)webViewDidStartLoad:(UIWebView *)webView
{
    if (_isFirst ) {
        [webView stopLoading];
    }else{
    
        _isFirst = !_isFirst;
    }
    
    // 禁用用户选择
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    
    // 禁用长按弹出框
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
    
    [self.juhua startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self.juhua stopAnimating];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
